
// https://leetcode.cn/problems/remove-nth-node-from-end-of-list
public class RemoveNthFromEnd {
    private static class ListNode{
        int val;
        ListNode next;
    }
    class Solution {
        public ListNode removeNthFromEnd(ListNode head, int n) {

            if(head == null) return null;
            ListNode dummy = new ListNode();
            dummy.next = head;
            ListNode fast = dummy;
            for(int i = 0 ; i < n ; i ++){
                fast = fast.next;
            }
            ListNode cur = dummy;
            while(fast.next != null){
                cur = cur.next;
                fast = fast.next;
            }

            cur.next = cur.next.next;
            return dummy.next;

        }
    }
}
